﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.common.logicexe.activities
{
    public class ArchExe : ExeBase
    {
        private string _lastMemberName = "";
        public ArchExe() { _name = ConfigStrings.S_Arch; _readable = ConfigStrings.SR_Arch; }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();

            //if (!getUser().isActivityRunning(ActivityType.ArchEvent)) return next_hour();

            bool _onlySameColorTeam = conf.ContainsKey(ConfigStrings.samecolor) && conf[ConfigStrings.samecolor].ToLower().Equals("true");
            bool _selfCreateTeam = conf.ContainsKey(ConfigStrings.create) && conf[ConfigStrings.create].ToLower().Equals("true");
            string _upgrades = "";
            if (conf.ContainsKey(ConfigStrings.upgrade)) _upgrades = conf[ConfigStrings.upgrade];

            ActivityMgr mgr = ServiceFactory.getActivityManager();

            User u = _user;
            int gold_available = getGoldAvailable();
            int result = mgr.getArchInfo(_proto, _logger, ref gold_available, _onlySameColorTeam, _selfCreateTeam,
                _upgrades, ref _lastMemberName);
            if (result == 10)
            {
                u.removeActivity(ActivityType.ArchEvent);
                return next_day(); // no event today, see next day
            }
            u.addActivity(ActivityType.ArchEvent);
            if (result == 2) // no pieces now
            {
                return next_hour();
            }
            return 5 * 1000;
        }
    }
}
